{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Account Balance After Rounded Purchase"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #math"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数学"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: accountBalanceAfterPurchase"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #取整购买后的账户余额"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>一开始，你的银行账户里有&nbsp;<code>100</code>&nbsp;块钱。</p>\n",
    "\n",
    "<p>给你一个整数<code>purchaseAmount</code>&nbsp;，它表示你在一次购买中愿意支出的金额。</p>\n",
    "\n",
    "<p>在一个商店里，你进行一次购买，实际支出的金额会向 <strong>最近</strong>&nbsp;的&nbsp;<code>10</code>&nbsp;的 <strong>倍数</strong>&nbsp;取整。换句话说，你实际会支付一个&nbsp;<strong>非负</strong>&nbsp;金额&nbsp;<code>roundedAmount</code>&nbsp;，满足&nbsp;<code>roundedAmount</code>&nbsp;是&nbsp;<code>10</code>&nbsp;的倍数且&nbsp;<code>abs(roundedAmount - purchaseAmount)</code>&nbsp;的值 <strong>最小</strong>&nbsp;。</p>\n",
    "\n",
    "<p>如果存在多于一个最接近的 <code>10</code>&nbsp;的倍数，<strong>较大的倍数</strong>&nbsp;是你的实际支出金额。</p>\n",
    "\n",
    "<p>请你返回一个整数，表示你在愿意支出金额为<em>&nbsp;</em><code>purchaseAmount</code><em>&nbsp;</em>块钱的前提下，购买之后剩下的余额。</p>\n",
    "\n",
    "<p><strong>注意：</strong> <code>0</code>&nbsp;也是&nbsp;<code>10</code>&nbsp;的倍数。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>purchaseAmount = 9\n",
    "<b>输出：</b>90\n",
    "<b>解释：</b>这个例子中，最接近 9 的 10 的倍数是 10 。所以你的账户余额为 100 - 10 = 90 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>purchaseAmount = 15\n",
    "<b>输出：</b>80\n",
    "<b>解释：</b>这个例子中，有 2 个最接近 15 的 10 的倍数：10 和 20，较大的数 20 是你的实际开销。\n",
    "所以你的账户余额为 100 - 20 = 80 。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>0 &lt;= purchaseAmount &lt;= 100</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [account-balance-after-rounded-purchase](https://leetcode.cn/problems/account-balance-after-rounded-purchase/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [account-balance-after-rounded-purchase](https://leetcode.cn/problems/account-balance-after-rounded-purchase/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['9', '15']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        if (purchaseAmount==0):\n",
    "            return 100\n",
    "        if (purchaseAmount%10==5):\n",
    "            return 100-purchaseAmount-5\n",
    "        if (purchaseAmount%10<=4):\n",
    "            return 100-purchaseAmount+purchaseAmount%10\n",
    "        else:\n",
    "            return 100-purchaseAmount+purchaseAmount%10-10\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        return 100 - (purchaseAmount + 5) // 10 * 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        i=purchaseAmount%10\n",
    "        c=purchaseAmount-i\n",
    "        if i>=5:\n",
    "            c+=10\n",
    "        return 100-c\n",
    "            \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        a = (purchaseAmount // 10) * 10\n",
    "        b = (purchaseAmount // 10 + 1) * 10\n",
    "        if b - purchaseAmount <= purchaseAmount - a:\n",
    "            return 100 - b\n",
    "        else:\n",
    "            return 100 - a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        return 100 - (purchaseAmount+5)//10*10\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        Ihave=100\n",
    "        return int(Ihave-round(purchaseAmount+0.0000001,-1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        remain = purchaseAmount % 10\n",
    "        if remain < 5:\n",
    "            purchaseAmount -= remain\n",
    "        else:\n",
    "            purchaseAmount += 10 - remain\n",
    "        return 100-purchaseAmount"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        return 100 - (purchaseAmount + 5) // 10 * 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        remain = purchaseAmount % 10\n",
    "\n",
    "        if remain < 5:\n",
    "            purchaseAmount -= remain\n",
    "        else:\n",
    "            purchaseAmount += 10 - remain\n",
    "        \n",
    "        return 100-purchaseAmount"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        Ihave=100\n",
    "        return int(Ihave-round(purchaseAmount+0.000000000001,-1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        return 100 - (purchaseAmount + 5) // 10 * 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        high_digit, low_digit = divmod(purchaseAmount, 10)\n",
    "        return 100 - (high_digit + (0 if low_digit < 5 else 1)) * 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        remain = purchaseAmount % 10\n",
    "\n",
    "        if remain<5:\n",
    "            purchaseAmount -= remain\n",
    "        \n",
    "        else:\n",
    "            purchaseAmount += (10-remain)\n",
    "        \n",
    "        return 100-purchaseAmount"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        roundedAmount =  purchaseAmount  - remainder  if (remainder := purchaseAmount % 10) < 5 else purchaseAmount + 10 - remainder\n",
    "        return 100 - roundedAmount"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        k,r = purchaseAmount // 10,purchaseAmount%10\n",
    "        if r >= 5:\n",
    "            k += 1\n",
    "        return 100 - k*10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        n = purchaseAmount // 10\n",
    "        m = purchaseAmount % 10\n",
    "        if m < 5:\n",
    "            return 100 - n * 10\n",
    "        else:\n",
    "            return 100 - (n + 1) * 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        return 100 - (purchaseAmount + 5) // 10 * 10\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        acpay = 0\n",
    "        amount = 100\n",
    "        # 十位上的数\n",
    "        t = purchaseAmount // 10\n",
    "        # if t==0:\n",
    "        #     return 100-10\n",
    "        # else:\n",
    "        # 看余数\n",
    "        remain = purchaseAmount % 10\n",
    "        print(purchaseAmount)\n",
    "        if remain < 5:\n",
    "            return 100 - (purchaseAmount // 10) * 10\n",
    "        else:\n",
    "            return 100 - (t + 1) * 10\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        return 100 - round((purchaseAmount + .1) / 10) * 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        remain = purchaseAmount % 10\n",
    "        if remain < 5:\n",
    "            purchaseAmount -= remain\n",
    "        else:\n",
    "            purchaseAmount += 10 - remain\n",
    "        return 100-purchaseAmount"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        price = 0\n",
    "        for i in range(1,12):\n",
    "            \n",
    "            if abs(purchaseAmount-price)>=abs(purchaseAmount-i*10):\n",
    "                price = i*10\n",
    "            else:\n",
    "                return 100-price"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        num1 = purchaseAmount // 10\n",
    "        print(num1)\n",
    "        if purchaseAmount >= num1 * 10 + 5:\n",
    "            return 100 - (num1+1) * 10\n",
    "        else:\n",
    "            return 100 - num1 * 10\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        if purchaseAmount % 10 ==5:\n",
    "            return 100-ceil(purchaseAmount/10)*10\n",
    "        elif purchaseAmount % 10 <5:\n",
    "            return 100-(purchaseAmount//10)*10\n",
    "        else:\n",
    "            return 100-(purchaseAmount//10+1)*10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        count = 0\n",
    "        while purchaseAmount >= 5:\n",
    "            purchaseAmount -= 10\n",
    "            count += 1\n",
    "        count *= 10\n",
    "        return 100 - count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        t = 100 - purchaseAmount\n",
    "        if t%10>5:\n",
    "            return t-t%10+10\n",
    "        return t-t%10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        return 100 - (purchaseAmount + 5) // 10 * 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "          if purchaseAmount % 10 == 0:\n",
    "              return 100 - purchaseAmount\n",
    "\n",
    "          t = purchaseAmount // 10\n",
    "          g = t + 1 if purchaseAmount % 10 >= 5 else t\n",
    "\n",
    "          return 100 - g * 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        if purchaseAmount % 10 == 0:\n",
    "            return 100 - purchaseAmount\n",
    "        x = purchaseAmount // 10 * 10\n",
    "        bx = x + 10\n",
    "        res = bx if bx - purchaseAmount <= purchaseAmount - x else x\n",
    "        return 100 - res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        a,b=divmod(100-purchaseAmount,10)\n",
    "        return a*10 if  b<=5 else (a+1)*10\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        if purchaseAmount%10<5:\n",
    "            return 100-purchaseAmount//10*10\n",
    "        else:\n",
    "            return 100- purchaseAmount//10*10-10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        ans = 100\n",
    "        d, m = divmod(purchaseAmount, 10)\n",
    "        if m >= 5 :\n",
    "            d += 1\n",
    "        return ans - d*10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        return 100 - (purchaseAmount + 5) // 10 * 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        if str(purchaseAmount)[-1]=='5':\n",
    "              purchaseAmount+=1\n",
    "        a=round((purchaseAmount)/10,0)\n",
    "        return int(100-a*10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        return 100 - (purchaseAmount + 5) // 10 * 10\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        return 100-(purchaseAmount+5)//10*10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        if purchaseAmount % 10 >= 5:\n",
    "            purchaseAmount += (10 - purchaseAmount % 10)\n",
    "        else:\n",
    "            purchaseAmount -= purchaseAmount % 10\n",
    "\n",
    "        return 100 - purchaseAmount"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "         a=purchaseAmount//10\n",
    "         if purchaseAmount%10<5:\n",
    "            return 100-a*10\n",
    "         else:\n",
    "            return 100-(a+1)*10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        n = purchaseAmount // 10\n",
    "        m = purchaseAmount % 10\n",
    "        if m < 5:\n",
    "            return 100 - 10*n\n",
    "        elif m == 5:\n",
    "            return 100 - 10*(n+1)\n",
    "        elif m > 5:\n",
    "            return 100 - 10*(n+1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "          g = purchaseAmount // 10 + 1 if purchaseAmount % 10 >= 5 else purchaseAmount // 10\n",
    "\n",
    "          return 100 - g * 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        a = purchaseAmount//10\n",
    "        b = purchaseAmount % 10\n",
    "        if b>=5:\n",
    "            return 100 - (a+1)*10\n",
    "        else:\n",
    "            return 100 - a*10\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        Ihave=100\n",
    "        return int(Ihave-round(purchaseAmount+0.1,-1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        return 100-(purchaseAmount+5)//10*10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        Ihave=100\n",
    "        return int(Ihave-round(purchaseAmount+0.1,-1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        return 100-(purchaseAmount+5)//10*10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import math\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        num = purchaseAmount % 10\n",
    "        if num == 0:\n",
    "            return 100 - purchaseAmount\n",
    "        if num < 5:\n",
    "            return 100 - (purchaseAmount - num)\n",
    "        return 100 - (math.ceil(purchaseAmount / 10) * 10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        nums = 0\n",
    "        if purchaseAmount == 0:\n",
    "            return 100\n",
    "        else:\n",
    "            if purchaseAmount % 10 == 0:\n",
    "                nums += purchaseAmount // 10\n",
    "            else:\n",
    "                if purchaseAmount % 10 < 5:\n",
    "                    nums += purchaseAmount // 10\n",
    "                else:\n",
    "                    nums +=(purchaseAmount // 10 + 1)\n",
    "        return 100 - nums*10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        return 100 - round(purchaseAmount / 10 + 1e-6) * 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        if purchaseAmount % 10 <= 4:\n",
    "            return 100 -(purchaseAmount//10)*10\n",
    "        else:\n",
    "            return 100-(purchaseAmount//10 +1)*10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "\n",
    "        return 100 - (purchaseAmount + 5) // 10 * 10\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        return 100 - (purchaseAmount + 5) // 10 * 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int: \n",
    "        f=purchaseAmount\n",
    "        k=purchaseAmount%10\n",
    "        if k>=5:\n",
    "          k=f//10+1\n",
    "        else:\n",
    "          k=f//10\n",
    "        return 100-k*10      "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        return 100 - round(purchaseAmount / 10 + .001) * 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "      ans = 100 - purchaseAmount\n",
    "      if ans % 10 <= 5:\n",
    "        return ans - (ans % 10)\n",
    "      else:\n",
    "        return ans - (ans % 10) + 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        if purchaseAmount % 10 == 0:\n",
    "            return 100 - purchaseAmount\n",
    "        else:\n",
    "            y = purchaseAmount % 10  # 余数\n",
    "            if y >= 5:\n",
    "                roundedAmount = purchaseAmount + 10 - y\n",
    "            else:\n",
    "                roundedAmount = purchaseAmount - y\n",
    "            return 100 - roundedAmount\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        if (purchaseAmount % 10 == 0):\n",
    "            return 100-purchaseAmount\n",
    "\n",
    "        # print (purchaseAmount , purchaseAmount % 10 , purchaseAmount // 10)\n",
    "        if (purchaseAmount % 10 in [1, 2, 3, 4]):\n",
    "            roundedAmount = 10 * ( purchaseAmount // 10 )\n",
    "        else:\n",
    "            roundedAmount = 10 * ( purchaseAmount // 10 + 1)\n",
    "\n",
    "        return 100 - roundedAmount"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "          g = purchaseAmount // 10 + 1 if purchaseAmount % 10 >= 5 else purchaseAmount // 10\n",
    "\n",
    "          return 100 - g * 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        d, m = divmod(purchaseAmount, 10)\n",
    "        return 100 - d * 10 - (0 if m < 5 else 10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        return 100-10*((purchaseAmount+5)//10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "\n",
    "        if purchaseAmount % 10 == 0:\n",
    "            return 100 - purchaseAmount\n",
    "        \n",
    "        # print(purchaseAmount / 10)\n",
    "        # print(round(purchaseAmount / 10))\n",
    "        v1 = ceil(purchaseAmount / 10) * 10\n",
    "        d1 = v1 - purchaseAmount\n",
    "\n",
    "        v2 = v1 - 10\n",
    "        d2 = purchaseAmount - v2\n",
    "\n",
    "        return 100 - ( v1 if d1 <= d2 else v2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        if purchaseAmount%10==0:\n",
    "            return 100 - purchaseAmount\n",
    "        if purchaseAmount%10>=5:\n",
    "            purchaseAmount+=(10-purchaseAmount%10)\n",
    "        else:\n",
    "            purchaseAmount-=purchaseAmount%10\n",
    "        return 100 - purchaseAmount"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        roundedAmount = (purchaseAmount + 5) // 10 * 10\n",
    "        return 100 - roundedAmount\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int:\n",
    "        return 100 - (purchaseAmount + 5) // 10 * 10"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
